package com.wanger.swc.config.myBatisPlus.autoDDL.model;

import cn.hutool.core.collection.CollUtil;
import com.wanger.swc.util.validation.MyVerifyUtil;
import lombok.Getter;
import lombok.ToString;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * @Author: wanger
 * @Date: 2025/1/20 10:10
 * @Description: ddl表
 */
@Getter
@ToString
public class AutoDDlTable {
    /**
     * 实体类
     */
    private final Class<?> entity;
    /**
     * 表明
     */
    private final String tableName;

    /**
     * 表注释
     */
    private final String tableComment;

    /**
     * 字段
     */
    private final Map<String, AutoDDLColumn> columnMap = new LinkedHashMap<>();

    /**
     * 数据库有，但代码没有的字段列表
     */
    private final Set<String> columnSet = new HashSet<>();

    public AutoDDlTable(Class<?> entity, String tableName, String tableComment, Map<String, AutoDDLColumn> columnMap) {
        MyVerifyUtil.nullVerify(entity, "entity 不能为空！");
        MyVerifyUtil.nullVerify(tableName, "entity名称 不能为空！");
        MyVerifyUtil.nullVerify(tableName, "entity字段 不能为空！");
        this.entity = entity;
        this.tableName = tableName.toLowerCase();
        this.tableComment = tableComment;
        this.columnMap.putAll(columnMap);
    }

    public AutoDDlTable(Class<?> entity, String tableName, String tableComment, Map<String, AutoDDLColumn> columnMap, Set<String> columnSet) {
        this(entity, tableName, tableComment, columnMap);
        if (CollUtil.isNotEmpty(columnSet)) this.columnSet.addAll(columnSet);
    }
}
